<template>
  <div class="loading-container">
    <div class="loading-content">
      <!-- 抖音风格Logo动画 -->
      <div class="logo-animation">
        <div class="music-notes">
          <div class="note note1">♪</div>
          <div class="note note2">♪</div>
          <div class="note note3">♪</div>
        </div>
        <div class="logo-text">Starlight Whisper</div>
      </div>

      <!-- 加载指示器 -->
      <div class="spinner-container">
        <div class="spinner">
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
          <div class="spinner-ring"></div>
        </div>
      </div>

      <!-- 文字提示 -->
      <div class="loading-text">
        <p class="primary-text">正在验证身份</p>
        <p class="secondary-text">请稍候...</p>
      </div>

      <!-- 进度条 -->
      <!-- <div class="progress-bar">
        <div class="progress-fill"></div>
      </div> -->
    </div>
  </div>
</template>

<script>
export default {
  name: "Loading",
  created() {
    this.unwatch = this.$watch(
      () => this.$store.getters["loginUser/stateNow"],
      (newState) => {
        if (newState !== "loading" && newState === "logined") {
          this.$router.push(this.$route.query.redirect || { name: "Home" });
        }
      },
      { immediate: true }
    );
  },
  destroyed() {
    this.unwatch();
  },
};
</script>

<style scoped lang="less">
.loading-container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100vh;
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 100%);
  position: relative;
  overflow: hidden;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(
        circle at 10% 20%,
        rgba(255, 0, 128, 0.1) 0%,
        transparent 20%
      ),
      radial-gradient(
        circle at 90% 80%,
        rgba(0, 200, 255, 0.1) 0%,
        transparent 20%
      );
    z-index: 0;
  }
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
  width: 100%;
  max-width: 300px;
  padding: 20px;
}

.logo-animation {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 50px;

  .music-notes {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;

    .note {
      position: absolute;
      font-size: 36px;
      opacity: 0;
      animation: notesAnimation 3s infinite;

      &.note1 {
        color: #ff0080;
        animation-delay: 0s;
      }

      &.note2 {
        color: #00c8ff;
        animation-delay: 1s;
      }

      &.note3 {
        color: #ffcc00;
        animation-delay: 2s;
      }
    }
  }

  .logo-text {
    font-size: 32px;
    font-weight: 700;
    background: linear-gradient(45deg, #ff0080, #00c8ff);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 2px;
  }
}

.spinner-container {
  margin-bottom: 40px;
}

.spinner {
  position: relative;
  width: 60px;
  height: 60px;

  .spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 4px solid transparent;
    border-radius: 50%;

    &:nth-child(1) {
      border-top-color: #ff0080;
      animation: spinnerRotate 1.5s linear infinite;
    }

    &:nth-child(2) {
      border-right-color: #00c8ff;
      animation: spinnerRotate 1.5s linear infinite 0.2s;
    }

    &:nth-child(3) {
      border-bottom-color: #ffcc00;
      animation: spinnerRotate 1.5s linear infinite 0.4s;
    }

    &:nth-child(4) {
      border-left-color: #00ff99;
      animation: spinnerRotate 1.5s linear infinite 0.6s;
    }
  }
}

.loading-text {
  text-align: center;
  margin-bottom: 30px;

  .primary-text {
    color: #ffffff;
    font-size: 20px;
    font-weight: 500;
    margin: 0 0 8px 0;
  }

  .secondary-text {
    color: #aaaaaa;
    font-size: 16px;
    margin: 0;
  }
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;

  .progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #ff0080, #00c8ff);
    border-radius: 3px;
    transition: width 0.3s ease;
  }
}

@keyframes notesAnimation {
  0% {
    transform: translateY(20px) scale(0.5);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  50% {
    transform: translateY(-20px) scale(1.2);
    opacity: 0.8;
  }
  100% {
    transform: translateY(-40px) scale(0.5);
    opacity: 0;
  }
}

@keyframes spinnerRotate {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

// 响应式设计
@media (max-width: 480px) {
  .loading-content {
    padding: 15px;
  }

  .logo-animation {
    .music-notes {
      width: 80px;
      height: 80px;

      .note {
        font-size: 28px;
      }
    }

    .logo-text {
      font-size: 28px;
    }
  }

  .spinner {
    width: 50px;
    height: 50px;
  }

  .loading-text {
    .primary-text {
      font-size: 18px;
    }

    .secondary-text {
      font-size: 14px;
    }
  }
}
</style>
